<?php 
    global $curUser;
    $user = $this->view->user;
?>
<script>
    $(document).on('click', 'div.follow-prompt', function(e){
        var pl = new SOAPClientParameters();
        pl.add("userid1", "<?php echo $curUser->id; ?>");
        pl.add("userid2", "<?php echo $user->id; ?>");
        console.log(<?php echo $curUser->id; ?>);
        SOAPClient.invoke("m/", "checkFollow", pl, true, callback_checkFollow);
    });
    
    function callback_checkFollow(r){
        var pl = new SOAPClientParameters();
        pl.add("userid1", "<?php echo $curUser->id; ?>");
        pl.add("userid2", "<?php echo $user->id; ?>");
        if(r === "true"){
            SOAPClient.invoke("m/", "deleteFollow", pl, true, callback_deleteFollow);
        }else{
            pl.add("datecreated", "<?php echo date("Y-m-d"); ?>");
            SOAPClient.invoke("m/", "addFollow", pl, true, callback_addFollow);
        }
    }
    
    function callback_deleteFollow(r){
        if(r === "true"){
            $('a.follow').attr('style', "display: inherit;");
            $('a.unfollow').attr('style', "display: none;");
        }
    }
    
    function callback_addFollow(r){
        if(r !== 0){
            $('a.follow').attr('style', "display: none;");
            $('a.unfollow').attr('style', "display: inherit;");
        }
    }
</script>
<div class="full">
    <div class="profile vcard group followed-by-current-user">
        <a target="_blank"><div data-picture="" data-alt="Webshocker" data-class="photo">
             <img alt="<?php echo $user->name ?>" class="photo" src="<?php echo $this->baseUrl.$user->avatar->url ?>"></div>
        </a>
        <h1>
            <span class="fn edit">
                <a href="<?php echo $this->baseUrl . $user->username ?>"><?php echo $this->view->user->name ?></a>
            </span>
        </h1>

        <ul class="profile-details">
            <?php if ($user->address) : ?>
            <li>
                <a class="locality"><?php echo $user->address ?></a>
            </li>
            <?php endif; ?>
        </ul>
        <div style="<?php if($curUser->id == $user->id) echo "display: none;"; ?>" class="follow-prompt">
            <a class="follow" style="<?php if(Follow::checkFollow($curUser->id, $user->id) == "false") echo "display: inherit;"; else echo "display: none;";?>">
                <span>Follow</span>
            </a>
            <a class="unfollow" style="<?php if(Follow::checkFollow($curUser->id, $user->id) == "true") echo "display: inherit;"; else echo "display: none;";?>">
                <span>Following</span>
            </a>
        </div>
    </div>
</div>